define(function(require, exports, module) {
	console.log("百度地图");
	mui.plusReady(function() {
		var container = document.getElementById("container");
		var bottom_content = document.getElementById("bottom_content");
		var list_details = document.getElementById("list_details");
		var weather_list_details = document.getElementById("weather_list_details");
		var week_list_details = document.getElementById("week_list_details");
		var search_adress = document.getElementById("search_adress");
		var list_details_icon_class;
		var map = new BMap.Map("container");
		var point = new BMap.Point(116.404, 39.915);
		map.centerAndZoom(point, 15);
		var screen_height = screen.height;
		var opts_Navi = {
			offset: new BMap.Size(5, screen_height / 2)
		};
		var opts_Geo = {
			offset: new BMap.Size(10, 80),
			anchor: BMAP_ANCHOR_BOTTOM_LEFT
		};
		//缩放
		map.addControl(new BMap.NavigationControl(opts_Navi));

		//定位
		var geolocationControl = new BMap.GeolocationControl(opts_Geo);
		geolocationControl.addEventListener("locationSuccess", function(e) {
			console.log("定位成功");
		})
		geolocationControl.addEventListener("locationError", function(e) {
			mui.toast(e.message);
		})
		map.addControl(geolocationControl);
		var marker = new BMap.Marker(new BMap.Point(116.404, 39.915)); // 创建点
		
		//创建折线
//		var polyline = new BMap.Polyline([
//			new BMap.Point(116.399, 39.910),
//			new BMap.Point(116.405, 39.920),
//			new BMap.Point(116.425, 39.900)
//		], {
//			strokeColor: "blue",
//			strokeWeight: 2,
//			strokeOpacity: 0.5
//		}); 
//		map.addOverlay(polyline); 
		//自定义控件
		function ZoomControl() {
			this.defaultAnchor = BMAP_ANCHOR_BOTTOM_LEFT;
			this.defaultOffset = new BMap.Size(11, 130);
		}
		ZoomControl.prototype = new BMap.Control();
		ZoomControl.prototype.initialize = function(map) {
			var div = document.createElement("div");
			div.className="control_icon" +" " +"border_all_radius";
			div.style.backgroundColor = "white";
			div.onclick = function(e) {
				map.setZoom(map.getZoom() + 2);
				map.GeolocationControl();
			}
			map.getContainer().appendChild(div);
			return div;
		}
		var myZoomCtrl = new ZoomControl();
		map.addControl(myZoomCtrl);

		//自动定位到初始值
		//		window.setTimeout(function() {
		//			map.panTo(new BMap.Point(116.409, 39.918));
		//		}, 2000);　　

		bottom_content.addEventListener("tap", function() {
			list_details.style.display = "block";
			week_list_details.style.display = "none";
			html = "";
			for(var i = 0; i < 8; i++) {
				if(i == 1) {
					list_details_icon_class = "icon_left_h_4";
				} else if(i == 2) {
					list_details_icon_class = "icon_left_h_5";
				} else if(i == 3) {
					list_details_icon_class = "icon_left_h_6";
				} else if(i == 4) {
					list_details_icon_class = "icon_left_h_7";
				} else {
					list_details_icon_class = "icon_left_h_4";
				}
				html += '<li id="weather_list_select' + i + '" onclick="select_weather_info(' + i + ')" class="font_14 font_color_red white"><span class="' + list_details_icon_class + '">';
				html += '</span><span>4月17日 北京市昌平区南关橙色大风提醒</span><span class="icon_right"></span>';
				html += '</li><div class="div_line"></div>';
			}
			weather_list_details.innerHTML = html;
		})
		mui("#weather_list_details").on("tap", ".font_color_red", function() {
			select_weather_info(this.id);
		})
		//		jQuery("#weather_list_details").find("li").each(function(){
		//			jQuery(this).on("click",function(){
		//				alert(this.id)
		//			})
		//		})
		select_weather_info = function(e) {
			list_details.style.display = "none";
			week_list_details.style.display = "block";
			var select_point = new BMap.Point(116.417, 39.909);
			var myIcon = new BMap.Icon("../../images/a-2.png", new BMap.Size(80, 120));
			var marker = new BMap.Marker(select_point, {
				icon: myIcon
			});
			map.addOverlay(marker);
			//删除指定的覆盖物
			var os = map.getOverlays();
			for(var i = 0; i < os.length; i++) {
				if(os[i].toString() == "[object Circle]") {
//					map.removeOverlay(JSON.stringify(os[i]));
				}
			}
			var circle = new BMap.Circle(select_point, 1000, {
				fillColor: "blue",
				strokeWeight: 1,
				fillOpacity: 0.2,
				strokeOpacity: 0.3
			});
			map.addOverlay(circle);
		}

		search_adress.addEventListener("click", function() {
			list_details.style.display = "none";
			week_list_details.style.display = "none";
		})　　　　
		map.addEventListener("click", function() {
			list_details.style.display = "none";
			week_list_details.style.display = "none";
		});
	});
});